import { getManager } from 'typeorm'
import { User } from '../entity/User'
import { ResponseUtil } from '../helpers/ResponseUtil'
import api from '../helpers/wxApi'
import { KoaContext } from '../server'
// import { KoaContext } from '../server'

export class GeneralController {

  public async index(ctx: KoaContext) {
    const user = getManager().getRepository(User)
    // 在 user 表中查找 id === 1 的数据
    await user.findOne(1)
    ctx.type = 'text'
    api.testGet()
    return ResponseUtil.success({ data: 'Hello World!' })
  }

  public async helloWorld(ctx: KoaContext): Promise<ApiTypes.ApiBaseResult> {
    const wx = ctx.wx
    const accessToken = await wx.getAccessToken()
    return ResponseUtil.success(
      {
        data: { accessToken },
      })
  }

  public async getJwtPayload(ctx: KoaContext): Promise<ApiTypes.ApiBaseResult> {
    const token = await ctx.redis.getToken('token')
    return ResponseUtil.success({ data: token })
  }

}
